--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit f2181edee19a733d933a563ec6dae0dfb1b7634b
Parents : b5ab7b8
Author : Ivan <ivan@quad4.io>
Signature : Invalid signer <e46112d44649266d71fe2193e00a4710>, author is <ivan@quad4.io>
Date : 2026-07-13T08:52:15-05:00
feat(tests): implement test sharding for backend tests and update CI configuration
Changes
3 files changed, 28 insertions(+), 3 deletions(-)
Diff
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 18ccad8e..69dc5bab 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -99,11 +99,15 @@ jobs:
esac
backend-tests:
- name: Backend tests (Python 3.14)
+ name: Backend tests (Python 3.14) - Shard ${{ matrix.shard }} / 4
runs-on: ubuntu-latest
- timeout-minutes: 60
+ timeout-minutes: 20
permissions:
contents: read
+ strategy:
+ fail-fast: false
+ matrix:
+ shard: [0, 1, 2, 3]
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
@@ -117,6 +121,9 @@ jobs:
pnpm-version: ${{ env.PNPM_VERSION }}
- name: Run backend tests
+ env:
+ PYTEST_SHARD_INDEX: ${{ matrix.shard }}
+ PYTEST_TOTAL_SHARDS: 4
run: task test:backend
build-check:
diff --git a/Taskfile.yml b/Taskfile.yml
index 15c9341b..3a409c1b 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -250,7 +250,7 @@ tasks:
aliases: [test:be, test:be:full]
desc: Run Python tests (pytest, includes perf/memory profiling, same as GitHub CI)
cmds:
- - uv run pytest tests/backend -n auto --cov=meshchatx/src/backend
+ - uv run pytest tests/backend -n auto {{.PYTEST_ARGS | default ""}}
test:be:cov:
desc: Run Python tests with detailed coverage (includes performance and memory profiling tests)
diff --git a/tests/backend/conftest.py b/tests/backend/conftest.py
index fe56bac2..271e319d 100644
--- a/tests/backend/conftest.py
+++ b/tests/backend/conftest.py
@@ -290,3 +290,21 @@ async def fetch_api_csrf_headers(client):
def extend_meshchat_middlewares(aio_app, middlewares):
auth_mw, mime_mw, sec_mw, csrf_mw, ip_mw = middlewares
aio_app.middlewares.extend([auth_mw, mime_mw, sec_mw, csrf_mw, ip_mw])
+
+
+def pytest_collection_modifyitems(session, config, items):
+ shard_index = os.environ.get("PYTEST_SHARD_INDEX")
+ total_shards = os.environ.get("PYTEST_TOTAL_SHARDS")
+ if shard_index is not None and total_shards is not None:
+ try:
+ shard_index = int(shard_index)
+ total_shards = int(total_shards)
+ if total_shards > 1 and 0 <= shard_index < total_shards:
+ items.sort(key=lambda item: item.nodeid)
+ items[:] = [
+ item for i, item in enumerate(items)
+ if i % total_shards == shard_index
+ ]
+ except ValueError:
+ pass
+
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────